package club.menglinking.wechat.controller.adminController;

import club.menglinking.wechat.entity.Json;
import club.menglinking.wechat.service.adminservice.UserService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName LoginController
 * @Author wuxuan
 * @Date 2019/1/5 16:14
 * @Version 1.0
 * @Description
 **/
@RestController
@Slf4j
public class LoginController {

    @Autowired
    UserService userService;

    ObjectMapper mapper=new ObjectMapper();

    @PostMapping("/adminLogin")
    public String adminLogin(@RequestParam Map<String, String> parm) throws JsonProcessingException {
        Boolean islogin = userService.adminLogin(parm);
        Json json=new Json();
        if (islogin){
            json.setStatus(200);
            json.setData(null);
            json.setMsg("system is Login");
            throw new NullPointerException();
        }else {
            json.setStatus(400);
            json.setMsg("Login error");
            json.setData(null);
        }
        return mapper.writeValueAsString(json);
    }
}
